<?php /*a:1:{s:58:"D:\workspace\admin\application\admin\view\user\online.html";i:1747109556;}*/ ?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title></title>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all"/>
    <style>
        .layui-form-item .layui-input-inline {
            width: 150px;
        }
        .layui-form-label {
            padding: 9px 5px;
            width: auto;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <form class="layui-form layui-col-space5" id="sbumitForm">
                    <div class="layui-inline layui-show-xs-block">
                        <input type="text" name="id" placeholder="按用户ID搜索" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-inline layui-show-xs-block">
                        <input type="text" name="account" placeholder="按账号搜索" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-inline layui-show-xs-block">
                        <input type="text" name="nick_name" placeholder="按昵称搜索" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-inline layui-show-xs-block">
                        <input type="text" name="mobile" placeholder="按手机号搜索" autocomplete="off" class="layui-input">
                    </div>

                    <div class="layui-input-inline layui-show-xs-block" style="width: 120px">
                        <select name="login_platform">
                            <option value="">按登录设备</option>
                            <option value="0">WEB</option>
                            <option value="1">IOS</option>
                            <option value="2">安卓</option>
                        </select>
                    </div>
                    <!--
                    <div class="layui-input-inline layui-show-xs-block" style="width: 120px">
                        <select name="reg_source_id">
                            <option value="">按来源</option>
                            <?php foreach($source as $value): ?>
                            <option value="<?php echo htmlentities($value['id']); ?>"><?php echo htmlentities($value['url']); ?></option>
                            <?php endforeach; ?>
                        </select>
                    </div>-->

                    <div class="layui-input-inline layui-show-xs-block" style="width: 120px">
                        <select name="refresh" lay-filter="refresh">
                            <option value="">选择刷新</option>
                            <option value="60">一分钟</option>
                            <option value="300">五分钟</option>
                            <option value="600">十分钟</option>
                            <option value="1200">二十分钟</option>
                        </select>
                    </div>

                    <div class="layui-inline">
                        <span  class="layui-btn" id="submit"><i class="layui-icon">&#xe615;</i></span >
                    </div>
                </form>
            </div>
            <div class="layui-card">
                <div class="layui-card-body">
                    <table id="demo" lay-filter="test"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/layuiadmin/layui/layui.js"></script>
<script>
    var source = <?php echo $source_json;?>;
    var crontable_id = 0;
    layui.config({
        base: "/layuiadmin/"
        , version: "<?php echo config('other.ui_version'); ?>"
    }).extend({
        index: "lib/index", //主入口模块
    }).use(["table", "laydate", "form"], function () {
        $ = layui.jquery, form = layui.form, table = layui.table;
        form.on('select(refresh)', function (data) {
            if (crontable_id) {
                window.clearInterval(crontable_id);
            }
            if (data.value) {
                crontable_id = window.setInterval("table.render(tableConf())", data.value * 1000);
            }
        });

        $("#submit").click(function () {
            table.render(tableConf());
        });
        table.render(tableConf());
    });

    function tableConf() {
        return {
            elem: '#demo',
            id: '#demo',
            url: '/admin/user/online?' + $("#sbumitForm").serialize(),
            defaultToolbar: [
                'filter', 'print', {title: '提示', layEvent: 'LAYTABLE_EXCEL', icon: 'layui-icon-table'},
            ],
            page: {
                curr: 1   //默认从第一页开始搜索
            },
            method: "get",
            //where: $("#sbumitForm").serialize(),
            limit: 20,
            limits: [20, 30, 50],
            text: {
                none: '暂无相关数据！'//默认无数据
            },
            response: {
                statusName: 'code',
                statusCode: 0,
                msgName: 'msg',
                countName: 'count',
                dataName: 'list',
            },
            cols: [[ //表头
                {field: 'id', title: 'ID', width: "8%", align: "center",},
                {field: 'account', title: '账号', width: "10%", align: "center",},
                {field: 'nick_name', title: '昵称', width: "10%", align: "center",},
                {field: 'mobile', title: '手机号', width: "10%", align: "center",},
                {
                    field: 'avatar', title: '头像', width: "8%", align: "center", templet: function (d) {
                        if (d.avatar) {
                            return '<img style="display: block;margin:0px auto; height: 100%;" src= "' + d.avatar + '">';
                        }
                        return '无';
                    }
                },
                {
                    field: 'is_anchor', title: '账户类型', width: "8%", align: "center", templet: function (d) {
                        switch (d.is_anchor) {
                            case 0:
                                if (d.anchor_type == 3) {
                                    return '<span class="layui-badge layui-bg-orange">测试用户</span>';
                                }
                                return '<span class="layui-badge layui-bg-orange">用户</span>';
                        }
                        var html = "";
                        switch (d.anchor_type) {
                            case 1:
                                html = '<span class="layui-badge layui-bg-green">主播</span>';
                                break;
                            case 2:
                                html = '<span class="layui-badge layui-bg-red">公司主播</span>';
                                break;
                            case 3:
                                html = '<span class="layui-badge layui-bg-red">测试主播</span>';
                                break;
                        }

                        return html;
                    }
                },
                {
                    field: 'login_platform', title: '登录设备', width: "8%", align: "center", templet: function (d) {
                        switch (d.login_platform) {
                            case 0:
                                return '<span class="layui-badge layui-bg-red">WEB</span>';
                            case 1:
                                return '<span class="layui-badge layui-bg-blue">IOS</span>';
                            case 2:
                                return '<span class="layui-badge layui-bg-green">Android</span>';
                            default:
                                return " 未知";
                        }
                    }
                },
                {
                    field: 'last_login', title: '最近登录', width: "12%", align: "center", templet: function (item) {
                        return '<font style="font-size: 13px">' + item.last_login + '</font>';
                    }
                },
                {
                    field: 'last_ip', title: '登录IP', width: "12%", align: "center", templet: function (item) {
                        //fixed: "right",
                        return '<a target="_blank" href="https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&tn=baidu&wd=' + item['last_ip'] + '">' + item['last_ip'] + '</a>';
                    }
                },
                /***
                {
                    field: '', title: '访问隧道', width: "12%", align: "center", templet: function (item) {
                        if (source[item.reg_source_id]) {
                            return '<font style="font-size: 13px">' + source[item.reg_source_id]+ '</font>';
                        }
                        return '-';
                    }
                },**/
                {
                    field: 'regist_ip', title: '注册ip', width: "12%", align: "center", templet: function (item) {
                        return '<a target="_blank" href="https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&tn=baidu&wd=' + item['regist_ip'] + '">' + item['regist_ip'] + '</a>';
                    }
                },
                {
                    field: 'regist_time', title: '注册时间', width: "12%", align: "center", templet: function (item) {
                        return '<font style="font-size: 13px">' + item.regist_time + '</font>';
                    }
                },
                {
                    title: '操作', align: "center",fixed: "right", width:80, templet: function (item) {
                        return '<a class="layui-btn layui-btn-xs" style="background-color: red" onclick="kicked_out(' + item['id'] + ')"><i class="layui-icon"></i>踢出</a>';
                    }
                }
            ]],
            done: function (res, curr, count) {
                res.list.forEach(function (item, index) {

                });
            },
        };
    }

    function kicked_out(id) {
        layer.confirm('踢出该用户后， 该用户将在1个小时内不可登录平台？', {title: "提示"}, function (index) {
            $.ajax({
                type: "POST",//请求方式
                url: '/admin/user/kicked_out?id=' + id, //请求地址
                dataType: "json",//返回的数据类型
                //请求成功
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1, time: 2000}, function () {
                            window.location.reload();
                        });
                    } else {
                        layer.msg(data.msg, {icon: 2});
                    }
                },
                //请求失败，包含具体的错误信息
                error: function (e) {
                    if (e.responseJSON.msg) {
                        layer.msg(e.responseJSON.msg, {icon: 2});
                    }
                }
            });
        });
    }
</script>
</body>
</html>
